package cn.dida.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.dida.dao.LgsNodeDao;
import cn.dida.model.LgsNode;
import cn.dida.model.Pageable;
import cn.dida.service.LgsNodeService;

/**
 * <p>节点管理业务层 实现类</p>
 * @auther lisha
 * @date 2017-2-8 14:34:31
 */
@Service
public class LgsNodeServiceImpl implements LgsNodeService {
	@Autowired
	private LgsNodeDao lgsNodeDao;

	@Override
	public Boolean insertLgsNode(LgsNode lgsNode) {
		return lgsNodeDao.insertLgsNode(lgsNode) == 1;
	}

	@Override
	public Boolean updateLgsNode(int companyId, LgsNode lgsNode) {
		return lgsNodeDao.updateLgsNode(companyId, lgsNode) == 1;
	}

	@Override
	public Pageable<LgsNode> query(String name, Integer type, Integer sta, int companyId, int page) {
		Pageable<LgsNode> pageable = lgsNodeDao.query(name, type, sta, companyId, page);

		List<LgsNode> reList = new ArrayList<>();
		List<LgsNode> list = pageable.getResult();
		for( LgsNode node:list){
			List<Map<String,Object>> bizList = lgsNodeDao.getBiztypeByNode(node.getId(),companyId);
			node.setBizList(bizList);
			reList.add(node);
		}

		pageable.setResult(reList);
		return pageable;
	}

	@Override
	public LgsNode getLgsNodeById(int id, int companyId) {
		return lgsNodeDao.getLgsNodeById(id, companyId);
	}

	@Override
	public Boolean isExistsNode(int companyId, String name) {
		return lgsNodeDao.isExistsNode(companyId, name);
	}

	@Override
	public List<LgsNode> getNodeList(Integer companyId, int state) {
		return lgsNodeDao.getNodeList(companyId, state);
	}

	@Override
	public List<Map<String,Object>> getBiztype(Integer companyId){
		return lgsNodeDao.getBiztype(companyId);
	}

	@Override
	public List<Map<String,Object>> getBiztypeByNode(Integer nodeId,Integer companyId){
		return lgsNodeDao.getBiztypeByNode(nodeId,companyId);
	}


}
